package org.maiyodemo;

import org.apache.cxf.frontend.ClientProxy;
import org.maiyodemo.interceptor.AuthInterceptor;
import org.maiyodemo.ws.Cat;
import org.maiyodemo.ws.Entry;
import org.maiyodemo.ws.MaiyoWebService;
import org.maiyodemo.ws.MaiyoWs;
import org.maiyodemo.ws.StringCat;
import org.maiyodemo.ws.User;

public class Client {

	public static void main(String[] args) {
		MaiyoWebService factory = new MaiyoWebService();
		// 返回远程Webservice的代理
		MaiyoWs ws = factory.getMaiyoWsImplPort();
		// 增加客户端拦截器，实现权限验证
		org.apache.cxf.endpoint.Client client = ClientProxy.getClient(ws);
		client.getOutInterceptors().add(new AuthInterceptor("maiyo", "123321"));
//		client.getOutInterceptors().add(new LoggingOutInterceptor());
		// sayHi
		System.out.println(ws.sayHi("maiYo"));
		// getCatByUser
		User user = new User();
		user.setId(1);
		user.setUsername("maiyo");
		user.setPassword("123321");
		user.setAddress("沙坪坝");
		for (Cat cat : ws.getCatByUser(user)) {
			System.out.println(cat.getName() + ":" + cat.getColor());
		}
		// getAllCats
		StringCat stringCat = ws.getAllCats();
		for (Entry e : stringCat.getEntries()) {
			System.out.println(e.getKey() + e.getValue().getName());
		}
	}

}
